package com.easy.life.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;
/**
 * mybatis-plus的配置
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.setFieldValByName("gmt_create",new Date(),metaObject);
        this.setFieldValByName("gmt_modified",new Date(),metaObject);
        this.setFieldValByName("introduction","这个人很懒，什么都没有留下",metaObject);
        this.setFieldValByName("avatar","https://xiaoxu-blog.oss-cn-hangzhou.aliyuncs.com/picture/default_avatar.jpg",metaObject);
        this.setFieldValByName("status",1,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.setFieldValByName("gmt_modified",new Date(),metaObject);
    }
}
